package com.vvv.designpattern.ticket.proxy;

import com.vvv.designpattern.ticket.director.AbstractDirector;
import com.vvv.designpattern.ticket.director.Director;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author vvv
 * @date 2023-11-25 15 42
 * discription代理模式：旨在代理某个对象的职责，并且新增辅助的方法（和被代理类的主要业务逻辑无关的方法)
 */
@Component
public class DirectorProxy extends AbstractDirector {

    @Resource
    private Director director;

    @Override
    public Object buildTicket(String type, String productId, String content, String title, String bankInfo, String taxId) {
        // 前置处理，根据productId获取product，和验证bankInfo
        String product = this.getProduct(productId);
        if (bankInfo != null && !this.validateBankInfo(bankInfo)) {
            return null;
        }
        return director.buildTicket(type, product, content, title, bankInfo, taxId);
    }

    private String getProduct(String productId) {
        return "通过productId获取商品信息";
    }

    private boolean validateBankInfo(String bankInfo) {
        System.out.println("银行卡校验逻辑！");
        return true;
    }
}
